//ACCEPTED
#include <cstdio>

int x[101][101];
int v[101];
int n, m, soma;


int read(){
	int a, b, c, d, i, j;
	
	for(i=1;i<=m;i++){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		v[i]=d;
		for(j=a;j<=b;j++)
			x[i][j] = c;
	}
}

void process(){
	soma=0;
	int min, cus;
	int index, i, j, tot;
	
	for(i=1; i<=n;i++){
		cus=index=0;
		min=2000000000;
		for(j=1;j<=m;j++){
			if(x[j][i])
			if(x[j][i]<min){
				index = j;
				min=x[j][i];
			}
		}
		soma+=v[index];
	}
}

int main(){
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	scanf("%d %d", &n, &m);
	
	read();
	process();
	
	printf("%d", soma);
	
	return 0;
}
